import { getUrlParamByKey, ajaxAsync } from 'vue-xiaobu-utils'
import OrderDetailModel from '../models/OrderDetailModel'

/**
 * 获取定制班线订单详情
 *
 */
async function getOrderDetail(test = false) {
  let orderId = getUrlParamByKey('ORDER_NO')
  let sendObj = {
    ORDER_ID: orderId
  }
  let res
  if (test) {
    res = {
      ORDER_ID: '21354411',
      OUT_ORDER_NO: '2019090565630',
      ORDER_STATE: 0, // -2:交易关闭，-1:待支付，0:已支付
      PAY_FEE: '60.00',
      OP: [2, 1],
      CREATE_TIME: 1569945600000,
      PAYMENT: 'ALIPAY',
      STORE_ORDER: [
        {
          STORE_NAME: '直达快线售票厅',
          SKU_LIST: [
            {
              SKU_NAME: '次票',
              SKU_NUM: 4,
              SKU_PIC:
                'http://img2.imgtn.bdimg.com/it/u=321406759,120456193&fm=26&gp=0.jpg'
            }
          ]
        }
      ]
    }
  } else {
    res = await ajaxAsync('/order/query2', sendObj)
  }
  let skuName = res.STORE_ORDER[0].SKU_LIST[0].SKU_PROPS_NAME
    ? res.STORE_ORDER[0].SKU_LIST[0].SKU_PROPS_NAME.split(':')[1]
    : ''
  let body = new OrderDetailModel(
    res.ORDER_ID,
    res.OUT_ORDER_NO,
    res.ORDER_STATE,
    res.PAY_FEE,
    res.OP,
    res.STORE_ORDER[0].STORE_NAME,
    skuName,
    res.STORE_ORDER[0].SKU_LIST[0].SKU_NUM,
    res.STORE_ORDER[0].SKU_LIST[0].SKU_PIC,
    res.PAYMENT,
    res.PAYMENT_NAME,
    res.PAYMENT_TIME,
    res.CREATE_TIME
  )
  // console.error(body)
  return body
}
export { getOrderDetail }
